//
//  NetworkType.swift
//  XWClassroom
//
//  Created by xianquan on 2023/11/21.
//

import Foundation
import Alamofire

let commonBaseUrl = "http://admin.jichacha.vip/api"

/// 参数过多时，建议直接使用字典
public enum NetworkType{
    /// 获取图片
    case wxLogin(access_token: String, openid: String)
    case getWxAccessToken(code: String)
    case appleLogin(user: String, nickname: String)
    case bindPhone(phone: String, verify: String, token: String)
    case getAuthCode(phone: String)
    case resetPwd(phone: String, verify: String, password: String, password_confirm: String)
    case getUserInfo
    case updateUserInfo(headimg: String, realname: String, age: Int, gender: Int, remark: String)
    case getTreaty(type: String)
    case feedbackCate
    case feedback(gcode: String, content_img: String, content: String, cate_name: String)
    
    var method: Alamofire.HTTPMethod  {
        switch self {
        case .wxLogin, .appleLogin, .bindPhone, .getAuthCode, .resetPwd, .updateUserInfo, .feedback:
            return .post
        default:
            return .get
        }
    }
    
    var baseUrl: String{
        switch self{
        case .getWxAccessToken:
            return ""
        default:
            return commonBaseUrl
        }
        
    }
    
    var path: String {
        switch self {
        case .wxLogin:
            return "/wechat_login"
        case .getWxAccessToken:
            return "https://api.weixin.qq.com/sns/oauth2/access_token"
        case .appleLogin:
            return "/apple_login"
        case .bindPhone:
            return "/binding_phone"
        case .getAuthCode:
            return "/verify"
        case .resetPwd:
            return "/seek_password"
        case .getUserInfo:
            return "/user/info"
        case .updateUserInfo:
            return "/user/update"
        case .getTreaty:
            return "/get_treaty"
        case .feedbackCate:
            return "/feedback_cate"
        case .feedback:
            return "/feedback"
        }
    
    }
    
    var parameters: [String: Any] {
        switch self {
        case let .wxLogin( access_token, openid):
            return ["access_token": access_token, "openid": openid]
        case .getWxAccessToken(let code):
            return ["appid": wxAppId, "secret": wxAppSecret, "code": code, "grant_type": "authorization_code"]
        case let .appleLogin(user, nickname):
            return ["user": user, "nickname": nickname]
        case let .bindPhone(phone, verify, token):
            return ["phone": phone, "verify": verify, "token": token]
        case let .getAuthCode(phone):
            return ["phone": phone]
        case let .resetPwd(phone, verify, password, password_confirm):
            return ["phone": phone,"verify": verify, "password": password, "password_confirm": password_confirm]
        case .getUserInfo:
            return [:]
        case let .updateUserInfo(headimg, realname, age, gender, remark):
            return ["headimg": headimg, "realname": realname, "age": age, "gender": gender, "remark": remark]
        case let .getTreaty(type):
            return ["type": type]
        case .feedbackCate:
            return [:]
        case let .feedback(gcode, content_img, content, cate_name):
            return ["type": "0", "gcode": gcode, "content_img": content_img, "content": content, "cate_name": cate_name]
        }
    }
    
    var headerNeedChannelId: Bool {
        switch self {

        default:
            false
        }
    }
    
    var dataType: DataType {
        switch self {
        
        default:
            .raw
        }
    }

}

extension NetworkType {
    
    struct UploadInfo{
        let valueKey: String
        let name: String
        let fileName: String
        let mimeType: String
    }
    
    enum DataType {
        case raw
        case query
        case formData(info: UploadInfo?)
        case encoder
    }
}


@objc public enum NetworkOCType: Int {
    
    case smsCode
    
    
    var method: Alamofire.HTTPMethod  {
        switch self {
        
        default:
            return .get
        }
    }
    
    var path: String {
        switch self {
            
        case .smsCode:
            return "/auth/api/login/smscode"
        }
    }
    var baseUrl: String{
        switch self{
        case .smsCode:
            return appEnvironment.newBaseUrl
        default:
            return appEnvironment.oldBaseUrl
        }
        
    }
}
